import requests


def get_weather(city):
    url = 'http://jisutqybmf.market.alicloudapi.com/weather/query'
    appcode = '545e5b63ca6448e2a9bc325da77ca1f8'
    headers = {'Authorization': 'APPCODE ' + appcode}
    try:
        content = requests.get(url=url, params={'city': city}, headers=headers)
    except requests.exceptions.Timeout:
        return 'TimeoutError'
    except requests.exceptions.ConnectionError:
        return 'ConnectionError'
    except requests.exceptions.HTTPError:
        return 'HTTPError'
    except requests.exceptions.TooManyRedirects:
        return 'TooManyRedirects'
    except:
        return 'OtherError'
    else:
        if content.status_code == 200 and content.json():
            return content.json()
        else:
            return ''

ErrorList = ['TimeoutError', 'ConnectionError', 'HTTPError', 'TooManyRedirects', 'OtherError']

demo = get_weather('深圳')

if demo in ErrorList:
    print(demo)
else:
    test = demo.get("result")
    # 获取城市
    city = test.get('city')
    # 获取天气
    weather = test.get('weather')
    # 获取气温
    temp = test.get('temp')

print(city, weather, temp)